import Vue from 'vue'
//这里仅示范npm安装方式的引入，其它方式引入请看最上面【安装】部分
import Router from 'js_sdk/uni-simple-router/index.js'
import pages from '@/pages.js'
Vue.use(Router)
const myRouter =
	pages().pages.map(item => ({
		path: `/${item.path}`,
		meta: item.meta || {}
	}))
//初始化
const router = new Router({
	routes: myRouter
});
//全局路由前置守卫
router.beforeEach((to, from, next) => {
	const value = uni.getStorageSync('Authorization');
	if (!value && to.meta.needLogin) {
		next({
			path: '/pages/login/index',
			query: {
				redirect: to.path
			}
		})
	} else {
		next()
	}
 
})
// 全局路由后置守卫
router.afterEach((to, from) => {})
export default router;
